﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Yunwei.Domain.Models;

namespace Yunwei.Web.Areas.RRShop.Models
{
    public class StaffViewModel
    {
        public int Id { get; set; }

        [Required]
        [StringLength(20, MinimumLength = 2, ErrorMessage = "{2}到{1}个字符")]
        [Display(Name = "姓名")]
        public string Name { get; set; }

        [Required]
        [StringLength(200, MinimumLength = 5, ErrorMessage = "{2}到{1}个字符")]
        [Display(Name = "照片")]
        public string Avatar { get; set; }

        [Display(Name = "生日")]
        public short Birthday { get; set; }

        [Display(Name = "性别")]
        public short Sex { get; set; }

        [Required]
        [Display(Name = "薪资")]
        public decimal Salary { get; set; }

        [Display(Name = "擅长菜系")]
        public string Cuisine { get; set; }

        [Display(Name = "个人详述")]
        public string Description { get; set; }

        [Required]
        [Display(Name = "岗位")]
        public short Job { get; set; }

        [Required(ErrorMessage = "必填")]
        [StringLength(20, MinimumLength = 2, ErrorMessage = "{2}到{1}个字符")]
        [Display(Name = "简介")]
        public string Brief { get; set; }

        [Display(Name = "年龄")]
        public int Age
        {
            get 
            {
                return DateTime.Now.Year - Birthday;
            }
        }

        [Required]
        [Display(Name = "岗位")]
        public string JobToString
        {
            get
            {
                switch (Job)
                {
                    case 1:
                        return "厨师";
                    case 2:
                        return "服务员";
                    case 3:
                        return "大堂经理";
                    case 4:
                        return "收纳";
                    case 5:
                        return "清洁";
                    case 6:
                        return "墩子";
                    default:
                        return "其他";
                }
            }
        }

        private List<SelectListItem> jobs;
        public List<SelectListItem> Jobs
        {
            get
            {
                if (jobs == null)
                {
                    jobs = new List<SelectListItem>();
                    jobs.Add(new SelectListItem() { Text = "厨师", Value = "1" });
                    jobs.Add(new SelectListItem() { Text = "服务员", Value = "2" });
                    jobs.Add(new SelectListItem() { Text = "大堂经理", Value = "3" });
                    jobs.Add(new SelectListItem() { Text = "收纳", Value = "4" });
                    jobs.Add(new SelectListItem() { Text = "清洁", Value = "5" });
                    jobs.Add(new SelectListItem() { Text = "墩子", Value = "6" });
                    jobs.Add(new SelectListItem() { Text = "其他", Value = "9" });
                }
                return jobs;
            }
        }

        private List<Cuisine> cuisines;
        public List<Cuisine> Cuisines
        {
            get
            {
                if (cuisines == null)
                {
                    cuisines = new List<Cuisine>();
                    cuisines.Add(new Cuisine() { Id = 1, Name = "川菜" });
                    cuisines.Add(new Cuisine() { Id = 2, Name = "鲁菜" });
                    cuisines.Add(new Cuisine() { Id = 3, Name = "粤菜" });
                    cuisines.Add(new Cuisine() { Id = 4, Name = "苏菜" });
                    cuisines.Add(new Cuisine() { Id = 5, Name = "浙菜" });
                    cuisines.Add(new Cuisine() { Id = 6, Name = "闽菜" });
                    cuisines.Add(new Cuisine() { Id = 7, Name = "湘菜" });
                    cuisines.Add(new Cuisine() { Id = 8, Name = "徽菜" });

                    cuisines.Add(new Cuisine() { Id = 11, Name = "潮州菜" });
                    cuisines.Add(new Cuisine() { Id = 12, Name = "东北菜" });
                    cuisines.Add(new Cuisine() { Id = 13, Name = "本帮菜" });
                    cuisines.Add(new Cuisine() { Id = 14, Name = "赣菜" });
                    cuisines.Add(new Cuisine() { Id = 15, Name = "鄂菜" });
                    cuisines.Add(new Cuisine() { Id = 16, Name = "京菜" });
                    cuisines.Add(new Cuisine() { Id = 17, Name = "津菜" });
                    cuisines.Add(new Cuisine() { Id = 18, Name = "冀菜" });
                    cuisines.Add(new Cuisine() { Id = 19, Name = "豫菜" });
                    cuisines.Add(new Cuisine() { Id = 20, Name = "客家菜" });
                    cuisines.Add(new Cuisine() { Id = 21, Name = "清真菜" });
                }

                return cuisines;
            }
        }

        public int Restaurant_Id { get; set; }

        private Staff _staff;
        public Staff Staff
        {
            get
            {
                if (_staff == null)
                    _staff = new Staff()
                    {
                        Id = this.Id,
                        Avatar = this.Avatar,
                        Birthday = this.Birthday,
                        Cuisine = this.Cuisine,
                        Description = this.Description,
                        Job = this.Job,
                        Name = this.Name,
                        Restaurant_Id = this.Restaurant_Id,
                        Salary = this.Salary,
                        Sex = this.Sex,
                        Brief = this.Brief
                    };
                return _staff;
            }
        }

        public static StaffViewModel FromStaff(Staff staff)
        {
            var staffViewModel = new StaffViewModel()
            {
                Id = staff.Id,
                Avatar = staff.Avatar,
                Birthday = staff.Birthday,
                Cuisine = staff.Cuisine,
                Description = staff.Description,
                Job = staff.Job,
                Name = staff.Name,
                Restaurant_Id = staff.Restaurant_Id,
                Salary = staff.Salary,
                Sex = staff.Sex,
                Brief = staff.Brief
            };

            return staffViewModel;
        }
    }
}